# 不同目录下
# import sys
# sys.path.append(r'O:\python\Tkinter1')

# 同一目录，则上边的不用
import main
import tablex
import tkinter as tk
def main_win_quit(str):
    print(str)
    # myWindow.quit
    return


myWindow = tk.Tk()
# 设置标题
myWindow.title('我是李桂平Python GUI Learning')
# 设置窗口大小
width = 680+700
height = 300+600
# 获取屏幕尺寸以计算布局参数，使窗口居屏幕中央
screenwidth = myWindow.winfo_screenwidth()
screenheight = myWindow.winfo_screenheight()
alignstr = '%dx%d+%d+%d' % (width, height, (screenwidth-width)/2, (screenheight-height)/2)
myWindow.geometry(alignstr)
# 设置窗口是否可变长、宽，True：可变，False：不可变
myWindow.resizable(width=False, height=True)


# 创建一个标签，显示文本
# label1 = tk.Label(myWindow, text="user-name",bg='red',font=('Arial 12 bold'),width=20,height=5)
# label1.pack()
# label2 = tk.Label(myWindow, text="password",bg='green',width=20,height=5)
# label2.pack()


# 创建一个标签，显示图标
# logo = tk.PhotoImage(file="O:/python/Tkinter1/pic/2.gif")
# label3 = tk.Label(myWindow, image=logo, text="password",bg='green',width=730,height=555)
# label3.pack(side='top')

# 创建一个标签，显示文本 图标 一起
# logo = tk.PhotoImage(file="O:/python/Tkinter1/pic/2.gif")
# explanation = """At present, only GIF and PPM/PGM
# formats are supported, but an interface exists to allow additional image file
# formats to be added easily."""
# label4 = tk.Label(myWindow,compound='center',text=explanation,image=logo).pack(side="right")


# 创建两个按钮
# b1=tk.Button(myWindow, text='button1',bg="red", relief='raised', width=8, height=2)
# b1.grid(row=0, column=0, padx=5,pady=5)
# b2=tk.Button(myWindow, text='button2', font=('Helvetica 10 bold'),width=8, height=2)
# b2.grid(row=0, column=1, padx=5, pady=5)




# 创建按钮并绑定响应函数，输入半径，计算圆面积并输出，代码如下：
lable5 = tk.Label(myWindow, text="input").grid(row=0)
lable6 = tk.Label(myWindow, text="output").grid(row=1)
print("Entry控件布局")
entry1=tk.Entry(myWindow)
entry2=tk.Entry(myWindow)
entry1.grid(row=0, column=1)
entry2.grid(row=1, column=1)
str1 ="Quit按钮退出；Run按钮打印计算结果"
main.main_win_quit(str1)
main.main_win_quit(str1)
main.main_win_quit(str1)
main.main_win_quit(str1)
main.main_win_quit(str1)
main.main_win_quit(str1)
bu1 = tk.Button(myWindow, text='Quit', command=myWindow.quit).grid(row=2, column=0, padx=5, pady=5)
# bu2 = tk.Button(myWindow, text='Run', command=main.main_win_quit(str1)).grid(row=2, column=1,  padx=5, pady=5)
bu2 = tk.Button(myWindow, text='Run', command=tablex.printme(str1)).grid(row=2, column=1,  padx=5, pady=5)
print('创建按钮并绑定响应函数，输入半径，计算圆面积并输出')


# 用来获取复选框是否被勾选，通过chVarDis.get()来获取其的状态,其状态值为int类型 勾选为1
# chVarDis = 1
# print('text为该复选框后面显示的名称, variable将该复选框的状态赋值给一个变量，当state=disa')
# check1 = tk.Checkbutton(myWindow, text="Disabled", variable=chVarDis, state='disabled')
# print('该复选框是否勾选,select为勾选, deselect为不勾选')
# check1.select()
# print('sticky=tk.W 当该列中其他行或该行中的其他列的某一个功能拉长这列的宽度或高度时，')
# print('设定该值可以保证本行保持左对齐，N：北/上对齐 S：南/下对齐 W：西/左对齐 E：东/右对齐')
# check1.grid(column=0, row=0, sticky='w')
# chvarUn = 1
# check2 = tk.Checkbutton(myWindow, text="UnChecked", variable=chvarUn)
# check2.deselect()
# check2.grid(column=1, row=0, sticky='w')
# chvarEn = 1
# check3 = tk.Checkbutton(myWindow, text="Enabled", variable=chvarEn)
# check3.select()
# check3.grid(column=2, row=0, sticky='w')

# 创建一个菜单项，类似于导航栏，顶层菜单
menubar=tk.Menu(myWindow)
print('创建菜单项')
fmenu1=tk.Menu(myWindow)

print('如果该菜单是顶层菜单的一个菜单项，则它添加的是下拉菜单的菜单项。则他添加的是下拉菜单的菜单项。')
for item in ['新建','打开','保存','另存为']:
    fmenu1.add_command(label=item)

fmenu2=tk.Menu(myWindow)
for item in ['复制','粘贴','剪切']:
    fmenu2.add_command(label=item)

fmenu3=tk.Menu(myWindow)
for item in ['大纲视图','web视图']:
    fmenu3.add_command(label=item)

fmenu4=tk.Menu(myWindow)
for item in ["版权信息","其它说明"]:
    fmenu4.add_command(label=item)

print('add_cascade 的一个很重要的属性就是 menu 属性，它指明了要把那个菜单级联到该菜单项上，')
print('# 当然，还必不可少的就是 label 属性，用于指定该菜单项的名称')
menubar.add_cascade(label="文件",menu=fmenu1)
menubar.add_cascade(label="编辑",menu=fmenu2)
menubar.add_cascade(label="视图",menu=fmenu3)
menubar.add_cascade(label="关于",menu=fmenu4)

print('# 最后可以用窗口的 menu 属性指定我们使用哪一个作为它的顶层菜单')
myWindow.config(menu=menubar)



#创建一个Message
# whatever_you_do = "Only those who have the patience to do simple things per"
# msg = tk.Message(myWindow, text = whatever_you_do)
# msg.config(bg='lightgreen', font=('times', 20, 'italic'))
# msg.pack( )

# xxs = '明月出天山'
# tablex.printme(xxs)

print('# 进入消息循环')
myWindow.mainloop()

